#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
int main()
{
    printf("please input char device name /dev/<char device>\n");
    char char_device[20] = {0};
    int read_count = read(0, char_device, 19);
    if (read_count < 0)
    {
        perror(strerror(errno));
        exit(errno);
    };
    char *newline = strchr(char_device, '\n');
    if (newline)
    {
        *newline = 0;
    }
    else
    {
        printf("input is to long\n");
        exit(1);
    }
    printf("your char_device is %s\n", char_device);

    int fd = open(char_device, O_WRONLY);
    if (fd < 0)
    {
        perror(strerror(errno));
        exit(errno);
    }
    printf("please input your data:\n");
    char buf[10] = {0};
    read_count = read(0, buf, 9);
    if (read_count < 0)
    {
        perror(strerror(errno));
        exit(errno);
    };
    write(fd, buf, read_count);
}